package service

import (
	"evidence/sdkInit"
	"fmt"
	"github.com/hyperledger/fabric-sdk-go/pkg/client/channel"
	"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
)

type ProofData struct {
	FileName   string `json:"file_name"`
	FileHash   string `json:"file_hash"`
	FileType   string `json:"file_type"`
	UploadUser string `json:"upload_user"`
	FileSize   string `json:"file_size"`
	UploadDate string `json:"upload_date"`
}

type ServiceSetup struct {
	ChaincodeID string
	Client      *channel.Client
}

func InitService(chaincodeID, channelID string, org *sdkInit.OrgInfo, sdk *fabsdk.FabricSDK) (*ServiceSetup, error) {
	handler := &ServiceSetup{
		ChaincodeID: chaincodeID,
	}
	//prepare channel client context using client context
	clientChannelContext := sdk.ChannelContext(channelID, fabsdk.WithUser(org.OrgUser), fabsdk.WithOrg(org.OrgName))
	// Channel client is used to query and execute transactions (Org1 is default org)
	client, err := channel.New(clientChannelContext)
	if err != nil {
		return nil, fmt.Errorf("Failed to create new channel client: %s", err)
	}
	handler.Client = client
	return handler, nil
}
